﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GerbilLib;

namespace MediaGerbil
{
    public partial class Log : Form
    {
        public Log()
        {
            InitializeComponent();
            Logger.LogMessageEvent += new EventHandler<LogEventArgs>(Logger_LogMessageEvent);
        }

        private void Logger_LogMessageEvent(object sender, LogEventArgs e)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new MethodInvoker(() => LogMessage(e)));
            }
            else
                LogMessage(e);
        }

        private void LogMessage(LogEventArgs e)
        {
            txtLog.AppendText(string.Format("[{0}] {1}{2}", DateTime.Now.ToShortTimeString(), e.Message, Environment.NewLine));
            txtLog.SelectionStart = txtLog.TextLength;
            txtLog.SelectionLength = 0;
        }

        private void Log_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Hide();
        }
    }
}
